<?php
include_once 'admin-functions.php';
include_once '../functions.php';
$blog_db = "data.ini";
if ((isset($_SESSION['logged_in'])) && ($_SESSION['account_rank']<2)) {} else {header('Location: page.php');exit;}

/* Listing*/
if (isset($_GET['edit']) == 0 && isset($_GET['delete']) == 0 && isset($_GET['view']) == 0 && isset($_POST['id']) == 0)  {
	echo '<form action="page.php" method="GET">
	<input type="hidden" name="p" value="manage" />
		
	<input type="hidden" name="delete" value="yes" />
	<table>' . "\n";
	list_posts($blog_db);
	echo "\n" . '</table><input onclick="document = yes;" type="button" value="Select All" /><input type="submit" value="Delete" /></form>';
}

/* Preview */
if (isset($_GET['view']) && isset($_SESSION['logged_in'])) {
	echo preview($_GET['view'], $blog_db);
	echo '<div class="nav"><a href="page.php?p=manage">Back</a></div>';	
}

/* Edit */
if (isset($_POST['id']) && isset($_SESSION['logged_in'])) {


}

/* Delete */
if (isset($_GET['delete']) && $_SESSION['account_rank']<1 && isset($_SESSION['logged_in'])) {
	foreach($_GET as $key => $value) {
		if ($value=="on") {
			echo delete_post($key, $blog_db);
		}
	}
}

/* BEGIN THE EDIT PAGE */
if (isset($_GET['edit']) && isset($_SESSION['logged_in'])) {

}


/* Error */
if (isset($_GET['delete']) && $_SESSION['account_rank']>=3) { echo "<p><strong>Oops!</strong> Make sure you have permission to delete entries!</p>";}
if (isset($_GET['edit']) && $_SESSION['account_rank']>=3) { echo "<p><strong>Oops!</strong> Make sure you have permission to edit entries!</p>";}

?>